package com.gao.e_callable.a;

import java.util.Random;
import java.util.concurrent.*;

/**
 * @author gaopeng
 * @time 2021/03/18 17:47:45
 */
class T2 implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        int n = new Random().nextInt(10);
        // How to pass the n to main thread!!!
        System.out.println("子线程：" + n);
        try {
            Thread.sleep(3000);
        } catch(Exception e) {
            e.printStackTrace();
        }
        return n;
    }
}

public class App2 {
    public static void main(String[] args) throws ExecutionException, InterruptedException, TimeoutException {
        ExecutorService es =
                new ThreadPoolExecutor(1,2,0L,
                        TimeUnit.SECONDS, new ArrayBlockingQueue<>(3));


        Future<Integer> future = es.submit(new T2());

         System.out.println("主线程: " + future.get());
//        System.out.println("主线程: " + future.get(1, TimeUnit.SECONDS));
        es.shutdown();
    }
}
